package com.sk.skplanet.commute.controllers;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.actions.API_requestBus;
import com.sk.skplanet.commute.actions.Actions;
import com.sk.skplanet.commute.vo.API_RequestInfo;
import com.sk.skplanet.commute.vo.Data;
import com.sk.skplanet.commute.vo.StopInfo;

public class StopInfoController {
	public static LinearLayout makeInfo(final Context context, final StopInfo stopInfo) {
		final API_RequestInfo api_requestinfo = new API_RequestInfo();
		final StopInfo stopInfoToPass = stopInfo;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout_info = (LinearLayout) inflater.inflate(R.layout.view_stopinfo, null);

		final TextView textview_arriveTime = (TextView) layout_info.findViewById(R.id.textview_arrivaltime);
		final TextView textview_startTime = (TextView) layout_info.findViewById(R.id.textview_starttime);
		final TextView textview_lastTime = (TextView) layout_info.findViewById(R.id.textview_lasttime);
		final TextView textview_arrivalstop = (TextView) layout_info.findViewById(R.id.textview_arrivalstop);

		TextView textview_busNum = (TextView) layout_info.findViewById(R.id.textview_busNum);
		final TextView[] textViewArr = { textview_busNum, textview_arriveTime, textview_startTime, textview_lastTime,
				textview_arrivalstop };

		layout_info.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				textview_arriveTime.setText("");
				new API_requestBus(context, stopInfo.getStop_id(), api_requestinfo, textViewArr).execute(
						"getArrInfoByRouteAll", stopInfo.getBus_id()); // 호출 함수 이름, 호출 함수 인자
			}
		});
		
		layout_info.setOnLongClickListener(new OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) {
				DialogController.createDeleteDialog(context, stopInfoToPass, v).show();
				return true;
			}
		});

		{// 인포 - busNum 텍스트뷰 설정 부분

			textview_busNum.setText(stopInfo.getBus_name());
			if (stopInfo.getBus_type() != null) textview_busNum.setTextColor(Color.parseColor(Actions
					.setBusTypeColor(stopInfo.getBus_type())));

			textview_busNum.setTextSize((float) Actions.DPFromPixel(15));
		}

		{// 인포 - busStop 텍스트뷰 설정 부분
			TextView textview_busStopStr = (TextView) layout_info.findViewById(R.id.textview_stopname);
			textview_busStopStr.setTextColor(Color.parseColor(Data.textview_routeColor));
			textview_busStopStr.setTextSize((float) Actions.DPFromPixel(12));
			textview_busStopStr.setText(Actions.setBusStopStr(stopInfo.getStop_name()));

			TextView textview_busStop = (TextView) layout_info.findViewById(R.id.textview_stopid);
			textview_busStop.setText(" (" + stopInfo.getStop_id() + ")");
			textview_busStop.setTextColor(Color.parseColor(Data.textview_routeColor));
			textview_busStop.setTextSize((float) Actions.DPFromPixel(12));
		}

		{// 인포 - 도착 예정 시간 텍스트뷰 설정 부분

			textview_arriveTime.setText(api_requestinfo.getArrivalTime());
			textview_arriveTime.setTextColor(Color.parseColor(Data.textview_arriveTimeColor));
			textview_arriveTime.setTextSize((float) Actions.DPFromPixel(12));

			{
				new API_requestBus(context, stopInfo.getStop_id(), api_requestinfo, textViewArr).execute(
						"getArrInfoByRouteAll", stopInfo.getBus_id()); // 호출 함수 이름, 호출 함수 인자
			}

		}

		return layout_info;
	}
}
